package com.waghost.bridalgown.controller;

import com.waghost.bridalgown.annotaion.Logging;
import com.waghost.bridalgown.entity.BridalGown;
import com.waghost.bridalgown.entity.Result;
import com.waghost.bridalgown.service.BridalGownService;
import com.waghost.bridalgown.utils.UserUtils;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
// 婚纱
@RestController
@CrossOrigin
@AllArgsConstructor
@RequestMapping("/bg")
public class BridalGownController {

    private BridalGownService bridalGownService;
    private UserUtils utils;

    @GetMapping("/list")
    public Result list(Integer category) {
        return bridalGownService.list(category);
    }

    // 获取首页推荐婚纱
    @GetMapping("/listTop")
    public Result listTop() {
        return bridalGownService.listTop();
    }

    @GetMapping("/get/{id}")
    @Logging(type = 4, uuid = 2)
    public Result get(@PathVariable("id") Integer id) {
        return bridalGownService.getId(id);
    }

    // 通过分类id，获取婚纱
    @GetMapping("/category/{categoryId}")
    public Result listCategory(@PathVariable("categoryId") Integer id) {
        return bridalGownService.listByCategory(id);
    }

    @PostMapping("/add")
    @Logging(type = 1,uuid = 2)

    public Result addUser(@RequestBody BridalGown bridalGown, HttpServletRequest request) {
        bridalGown.setCreateUser(utils.getUser(request).getId());
        return bridalGownService.add(bridalGown);
    }

    @PostMapping("/edit")
    @Logging(type = 3,uuid = 2)
    public Result editUser(@RequestBody BridalGown bridalGown) {
        return bridalGownService.update(bridalGown);
    }

    @PostMapping("/del/{id}")
    @Logging(type = 2,uuid = 2)
    public Result delUser(@PathVariable("id") Integer id) {
        return bridalGownService.delete(id);
    }


}
